﻿using System;
using System.Collections.Generic;
using WorkFlow.Engine.NSActivity;

namespace WorkFlow.Engine.NSUtilities
{
    public class WfCleaner
    {
        public static void Recycle(List<WfActivity> list, List<WfActivity> newActs)
        {
            TimeSpan unLockSpan = TimeSpan.Parse("00:05:00"); //mins 5分钟接触锁定
            TimeSpan removeSpan = TimeSpan.Parse("00:10:00"); //mins 10分钟移除未使用活动

            //----------解除活动锁定
            var dtNow = new DateTime();
            if (list.Count > 0)
            {
                foreach (WfActivity v in list)
                {
                    if (dtNow - v.LastVisitedDateTime < unLockSpan) continue;
                    v.LockOwner = WfFieldCode.DbNone;
                    v.LastVisitedDateTime = dtNow;
                    v.IsLocked = WfFieldCode.DbFalse;
                    newActs.Add(v);
                    list.Remove(v);
                }
            }
            if (newActs.Count <= 0) return;
            foreach (WfActivity v in newActs)
            {
                if (dtNow - v.LastVisitedDateTime < removeSpan) continue;
                newActs.Remove(v);
            }
        }
    }
}